<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: antiquewhite;}
  </style>
</head>
<body>
  <video id="vid" controls autoplay loop muted>
    <source src="./images/ripples.mp4" type="video/mp4">
  </video>
  <div>
    <canvas id="canvas" width="400" height="282"></canvas>
  </div>
  <script>
    /** @type {HTMLCanvasElement} */
    const vid = document.querySelector('#vid')
    const canvas = document.querySelector('#canvas');
    const ctx = canvas.getContext('2d');

    // 时间监听器
    let interval = null;

    /*
      视频事件
      视频播放: play
      暂停: pause
    */
   vid.addEventListener('play', function () {
     // 绘图
     interval = setInterval(() => {
       ctx.drawImage(vid,0,0);
     }, 40)
   });

   vid.addEventListener('pause', function () {
     clearInterval(interval);
   })

  </script>
</body>
</html>